﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;

namespace API.Controllers
{
    public class {subFolder}Controller  : BaseController
    {
	[folder start]

		#region {tblName}模块

		/// <summary>
        /// [tblTitle]查看
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public HttpResponseMessage {tblName}GetById(int id)
        {
            var bll = new BLL.[tblName]();
            var model = bll.GetById(id);
            if (model == null)
            {
                model = new Data.[tblName]();
                //model.Mobile = "100***";
            }
            return success(model);
        }

        /// <summary>
        /// [tblTitle]删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public HttpResponseMessage {tblName}Delete(int id)
        {
            var bll = new BLL.[tblName]();
            var model = bll.GetById(id);
            if (model == null) return error("对象不存在");
            else
            {
                bll.Delete(id);
                return success(model);
            }
        }

        /// <summary>
        /// [tblTitle]更新
        /// formData为参数传入json条件串
        /// </summary>
        /// <returns></returns>
		[HttpPost]
        public HttpResponseMessage {tblName}Edit()
        {
			HttpRequestBase request = ((HttpContextBase)Request.Properties["MS_HttpContext"]).Request;
            string formData = request.Form["formData"];
            var model = JsonConvert.DeserializeObject<Data.[tblName]>(formData);
            //新增记录的默认参数
            if (model.id <= 0)
            {
                //model.IsSystem = 999;
            }

            var bll = new BLL.[tblName]();
            var rows = bll.Update(model);
            if (rows >= 0) return success(model);
            else return error("失败");
        }

        /// <summary>
        /// [tblTitle]列表
        /// formData为参数传入json条件串
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public HttpResponseMessage {tblName}List()
        {
			HttpRequestBase request = ((HttpContextBase)Request.Properties["MS_HttpContext"]).Request;
            var filter = request.Form["filter"];
            var dic = JsonConvert.DeserializeObject<Dictionary<string,string>>(filter);
            //此处可加入条件
            //dic["adminId"] = "323";

            var bll = new BLL.[tblName]();
            var pager= bll.List(dic);
            return success(pager);
        }
 
		#endregion
	[folder end]
	}
}